package com.communal.web.form.tarif;

import net.sf.ezmorph.bean.MorphDynaBean;
import net.sf.json.JSONObject;

import com.communal.model.tarif.TarifElectricity;
import com.communal.web.form.BaseForm;

/**
 * 
 * @author Created by andrey.kuznetsov <br>
 * @author Last modified by $Author$ <br>
 * @author Last modified on $Date$ at revision $Revision$ <br>
 */
public class TarifElectricityForm extends BaseForm{

	private final String TARIF_NAME = "tarifName";
	private final String UNDER_SUMMA = "underSumma";
	private final String OVER_SUMMA = "overSumma";
	private final String BORDER_VALUE = "borderValue";
	
	private String tarifName;
	private Double underSumma;
	private Double overSumma;
	private Short borderValue;
	
	/**
	 * Constructor from JSON data for {@link TarifElectricityForm} <br>
	 * @param p_data - JSON data
	 */
	public TarifElectricityForm(Object p_data) {
		super( p_data, true );
		JSONObject jsonObject = JSONObject.fromObject(p_data);
		MorphDynaBean bean = (MorphDynaBean) JSONObject.toBean(jsonObject);
		tarifName = bean.get(TARIF_NAME).toString();
		underSumma = Double.parseDouble(bean.get(UNDER_SUMMA).toString());
		overSumma = Double.parseDouble(bean.get(OVER_SUMMA).toString());
		borderValue = Short.parseShort(bean.get(BORDER_VALUE).toString());
	}

	/**
	 * Constructor from electricity tarif model <br>
	 * @param p_tarifElectricity - electricity tarif model; {@link TarifElectricity}
	 */
	public TarifElectricityForm(TarifElectricity p_tarifElectricity) {
		super( p_tarifElectricity );
		tarifName = p_tarifElectricity.getTarifName();
		underSumma = p_tarifElectricity.getUnderSumma();
		overSumma = p_tarifElectricity.getOverSumma();
		borderValue = p_tarifElectricity.getBorderValue();
	}

	/**
	 * Returns tarif name <br>
	 * @return {@link String};
	 */
	public String getTarifName() {
		return tarifName;
	}

	/**
	 * Sets tarif name <br>
	 * @param p_tarifName - {@link String};
	 */
	public void setTarifName(String p_tarifName) {
		tarifName = p_tarifName;
	}

	/**
	 * Returns under summa (summa per kWatt which should user pay if he not reached border limit)
	 * @return {@link Double};
	 */
	public Double getUnderSumma() {
		return underSumma;
	}

	/**
	 * Sets under summa (summa per kWatt which should user pay if he not reached border limit) <br>
	 * @param p_underSumma - {@link Double};
	 */
	public void setUnderSumma(Double p_underSumma) {
		underSumma = p_underSumma;
	}

	/**
	 * Returns over summa (summa per kWatt which should user pay if he exceed border limit) <br>
	 * @return {@link Double};
	 */
	public Double getOverSumma() {
		return overSumma;
	}

	/**
	 * Sets over summa (summa per kWatt which should user pay if he exceed border limit) <br>
	 * @param p_overSumma - {@link Double};
	 */
	public void setOverSumma(Double p_overSumma) {
		overSumma = p_overSumma;
	}

	/**
	 * Returns border value <br>
	 * @return {@link Short};
	 */
	public Short getBorderValue() {
		return borderValue;
	}

	/**
	 * Sets border value <br>
	 * @param p_borderValue - {@link Short};
	 */
	public void setBorderValue(Short p_borderValue) {
		borderValue = p_borderValue;
	}
	
}
